package com.xiaoerkeji.eshop;

import android.text.TextUtils;


import com.lt.app.AppHelper;
import com.lt.app.PreferencesHelper;
import com.lt.app.ResHelper;
import com.lt.common.DebugHelper;

import java.lang.ref.SoftReference;

/**
 * 配置和重要信息缓存
 *
 * @author luotian
 */
public class xeSetting
{

    private static final String key_show_loading = "key_show_loading";
    public static final String key_save_pwd = "key_save_pwd";
    public static final String key_save_user = "key_save_user";
    public static final String key_user_token = "key_user_token";
    public static final String key_user_info = "key_user_info";
    public static final String key_role_index = "key_role_index";
    public static final String key_identify_checked = "key_identify_checked";
    public static final String key_multiple_role_tip = "key_multiple_role_tip"; //多角色选择提示
    public static final String key_cache_version = "key_cache_version"; //缓存版本号
    public static final String key_web_version = "key_web_version";

    private static xeSetting _setting;
    private static SoftReference<Boolean> _identify;
    private int mRoleIndex; //角色序号
    private boolean isX5Load = false; //腾讯x5浏览器内核是否成功加载

    private xeSetting()
    {
        init();
    }

    private void init()
    {
        mRoleIndex = getPreference().getInt(key_role_index, 0);
    }

    public static xeSetting getInstance()
    {
        if (_setting == null)
        {
            _setting = new xeSetting();
        }
        return _setting;
    }

    public PreferencesHelper getPreference()
    {
        return PreferencesHelper.getInstance("cd_yuanma_lslsfh");
    }


    public boolean isX5Load()
    {
        return isX5Load;
    }

    public void setX5Load(boolean x5Load)
    {
        isX5Load = x5Load;
    }














    public void setIdentifyChecked(boolean isChecked)
    {
        _identify = new SoftReference<>(isChecked);
        getPreference().put(key_identify_checked, isChecked);
    }

    public boolean isIdentifyChecked()
    {
        if (_identify != null && _identify.get() != null)
        {
            return _identify.get();
        }
        return getPreference().getBoolean(key_identify_checked, true);
    }

    public int getRoleIndex()
    {
        return mRoleIndex;
    }

    public void setRoleIndex(int roleIndex)
    {
        this.mRoleIndex = roleIndex;
        getPreference().putInt(key_role_index, roleIndex);
    }





    public int getCacheVersion()
    {
        return getPreference().getInt(key_cache_version, 0);
    }

    public void setCacheVersion()
    {
        getPreference().putInt(key_cache_version, AppHelper.getInstance().getAppVersionCode());
    }

    public void setVersion(int version)
    {
        getPreference().putInt(key_web_version, version);
    }

    public int getVersion()
    {
        return getPreference().getInt(key_web_version, 0);
    }
}
